<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">潜客看板</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar ref="toolbar"  class="toolbar" @search="handleFind"
                            areaTeam campusTeam studentName phoneNo alloCreateTime priority
          ></customer-toolbar>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              maxHeight="600"
              empty-text="暂无数据"
              stripe
              style="min-width: 100%">
              <el-table-column
                min-width="100"
                prop="studentName"
                label="学生姓名">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="phoneNo"
                label="电话号码">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="sex"
                label="性别">
                <template scope="scope">
                  <div v-if="scope.row.sex">{{scope.row.sex === '1' ? '男' : '女'}}</div>
                  <div v-else>未设置</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="projectName"
                label="项目活动名称">
              </el-table-column>
              <el-table-column
                min-width="120"
                prop="projectTime"
                label="项目活动日期">
                <template scope="scope">
                  <div>{{scope.row.projectTime | formatDate}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="priority"
                label="紧急程度">
                <template scope="scope">
                  <div>{{{'0' : '低' ,'1': '中', '2': '高'}[scope.row.priority]}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="campusName"
                label="意向校区">
              </el-table-column>
              <el-table-column
                min-width="165"
                prop="alloCreateTime"
                label="分配时间">
                <template scope="scope">
                  <div>{{scope.row.alloCreateTime | formatTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="gradeName"
                label="就读年级">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="bigCategory"
                label="来源大类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="smallCategory"
                label="来源小类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="remark"
                label="备注信息">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="areaTeamName"
                fixed="right"
                label="操作">
                <template scope="scope">
                  <el-button size="small" :disabled="scope.row.followStatus === '1'"
                             v-if="hasPermission('get')" @click="handleGrab(scope.row.customerResourceId)">抢占资源</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="loadTableData"/>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
<script>
  import io from '../../lib/io'
  import CustomerToolbar from './CustomerToolbar.vue'
  import Pagination from '../base/Pagination.vue'
  import moment from 'moment'
  import ElButton from "../../../node_modules/element-ui/packages/button/src/button.vue";

  export default{
    data:function(){
      return {
        total: 0,
        pageSize: 10,
        pageNo: 1,
        tableData: [{}],
      }
    },
    components: {
      ElButton,
      CustomerToolbar, Pagination
    },
    watch: {

    },
    computed: {

    },
    mounted :function(){
      $(window).smoothScroll()
//      this.loadTableData()
    },
    methods:{
      handleGrab (customerResourceId) {
        this.$confirm('确定抢占该资源？',() => {
          io.post(io.takeCustomerResource, {
            customerResourceId: customerResourceId
          }, (ret) => {
            if (ret.success) {
              this.$toast('抢占成功！')
              this.loadTableData()
            } else {
              this.$alert(ret.desc)
            }
          })
        })
      },
      handleFind(formData) {
        this.formData = this.formatData(formData);
        this.loadTableData(1)
      },
      loadTableData: function (pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.$showLoading()
        io.post(io.customerResourceForDashboard, Object.assign({}, this.formData, {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
        }), (ret) => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      formatData(data) {
        return {
          areaTeamId: data.areaTeamId,
          campusId: data.campusId,
          priority: data.priority,
          alloStatus: 1,
          followStatus: 0,
          studentName: data.studentName,
          phoneNo: data.phoneNo,
          alloCreateTimeOfStart: data.alloCreateTime[0] ? moment(data.alloCreateTime[0]).format('YYYY-MM-DD') : '',
          alloCreateTimeOfEnd: data.alloCreateTime[1] ? moment(data.alloCreateTime[1]).format('YYYY-MM-DD') : '',
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
